﻿using AutoMapper;
using Esosi.Balance.Bll;
using Esosi.Balance.Bll.ClinicBalance.Register;
using Esosi.Balance.Bll.Dtos;
using Esosi.Balance.Bll.Models.Hospital;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace Esosi.Balance.TestConsole
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var tpid = new RegisterTpiDto
            {
                PatientInfoDto = new PatientInfoDto
                {
                    PatientName = "Sss"
                },
                BalanceSource = BalanceSource.Person
            };

            //RegisterHospital registerHospital = new RegisterHospital();
            //var tpod = registerHospital.BalanceCalc(tpid);

            //Console.WriteLine(tpod.MustPay);

            //setup our DI
            //var serviceCollection = new ServiceCollection();
            //.AddLogging()
            //.AddSingleton<IFooService, FooService>()
            //.AddSingleton<IBarService, BarService>()
            // .AddSingleton<BalanceBase, RegisterHospital>()
            //.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies())
            //    .BuildServiceProvider();

            //configure console logging
            //serviceProvider
            //    .GetService<ILoggerFactory>()
            //    .AddConsole(LogLevel.Debug);

            //var logger = serviceProvider.GetService<ILoggerFactory>()
            //    .CreateLogger<Program>();
            //logger.LogInformation("Starting application");

            ////do the actual work here
            //var bar = serviceProvider.GetService<IBarService>();
            //bar.DoSomeRealWork();
            //serviceCollection.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies())
            //.AddSingleton<BalanceBase, RegisterHospital>();

            //var serviceProvider = serviceCollection.BuildServiceProvider();
            //var registerHospital = serviceProvider.GetService<BalanceBase>();
            var registerHospital = GetBalance(tpid.BalanceSource);
            var tpod = registerHospital.BalanceCalc(tpid);
            Console.WriteLine(tpod.MustPay);

            //logger.LogInformation("All done!");
        }

        private static BalanceBase GetBalance(BalanceSource balanceSource)
        {
            var serviceCollection = new ServiceCollection()
             .AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

            switch (balanceSource)
            {
                case BalanceSource.Person:
                    serviceCollection.AddSingleton<BalanceBase, RegisterHospital>();
                    break;

                case BalanceSource.ShangHaiMedical:
                    break;

                default:
                    break;
            }

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var registerHospital = serviceProvider.GetService<BalanceBase>();
            return registerHospital;
        }
    }
}